<template>
  <div>
    <t-table
      rowKey="id"
      :data="data"
      :columns="columns"
      hover
      :pagination="pagination"
      :loading="dataLoading"
    >
      <template #name="{row}">
        <t-link @click="dialog.objId=row.id;dialog.header=row.name;dialog.open_review=true" hover="color" theme="primary">{{row.name}}</t-link>
      </template>
      <template #awardsMemberList="{ row }">
        <template v-for="(item,index) in row.awardsMemberList">
          <a class="t-button-link"  :key="index">{{item.name}}</a>{{index+1===row.awardsMemberList.length?'':'、'}}
        </template>
      </template>
      <template #awardsProjectList="{ row }">
        <template v-for="(item,index) in row.awardsProjectList">
          <a class="t-button-link"  :key="index">{{item.businessName}}</a>{{index+1===row.awardsProjectList.length?'':'、'}}
        </template>
      </template>
      <template #awardsType="{ row }">
        {{ row.awardsType | filterByDict(dict.type.awards_type) }}
      </template>
      <template #awardsLevel="{ row }">
        {{ row.awardsLevel | filterByDict(dict.type.awards_level) }}
      </template>
      <template #awardsGrade="{ row }">
        {{ row.awardsGrade | filterByDict(dict.type.awards_grade) }}
      </template>
      <template #awardsStatus="{ row }">
        <t-tag @click="dialog.header=row.name;dialog.objId=row.id;dialog.open_approve_list=true" class="cursor-pointer"
               :theme="handleTheme(row.awardsStatus, dict.type.achievement_status)" variant="light">
          {{ row.awardsStatus | filterByDict(dict.type.achievement_status) }}
        </t-tag>
      </template>
      <template #op="{ row }">
        <t-button size="small"
                  @click="dialog.objId=row.id;dialog.header=row.name;dialog.open_detail=true"
                  variant="text" class="t-button-link">
          <t-icon name="info-circle" slot="icon"/>
          详情
        </t-button>
      </template>
    </t-table>
    <awards-detail-dialog :objId="dialog.objId" :header="dialog.header" :visible.sync="dialog.open_detail" v-if="dialog.open_detail">
    </awards-detail-dialog>
    <file-review :header="dialog.header" :projectFileData="projectFileData" :visible.sync="dialog.open_review" v-if="dialog.open_review" :objId="dialog.objId"></file-review>
  </div>
</template>

<script>
// import awardsDetailDialog from "../../../cgzh/awards/components/awards-detail-dialog.vue";
import fileReview from "../../../cgzh/components/file-review.vue";

export default {
  name: "awards-list",
  dicts: ['awards_level', 'awards_grade', 'achievement_status','awards_type'],
  props: ['deptId', 'idCard'],
  components: {
    // awardsDetailDialog,
    awardsDetailDialog: () => import('../../../cgzh/awards/components/awards-detail-dialog.vue'),

    fileReview
  },
  data() {
    return {
      projectFileData: [
        {
          id: 1,
          c1: "获奖证书",
          c2: "是",
          moduleKey: "awardsZS",
          fileIds: [],
          fileLists: [],
          require: true,
        },
      ],
      dialog: {
        header: "",
        open: false,
        objId: null,
        open_approve_list: false,
        open_detail: false,
        open_review: false,
      },
      serviceOptions: [],
      projectOptions: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: "",
        awardsLevel: '',
        awardsGrade: '',
        awardsDate: '',
        publishDept: '',
        startAwardsDate: '',
        endAwardsDate: '',
        awardsDateRange: [],
        declareDeptName: '',
        awardsStatus: '',
        peopleName: '',
        businessName: '',
        status: "",
        dateRange: [],
        serviceCode: '',
        businessId: null,
        awardsType: '',
        deptId: this.deptId,
        idCard: this.idCard,
      },
      data: [],
      columns: [
        {
          colKey: "name",
          title: "奖励名称",
          align: "center"
        },
        {
          colKey: "awardsProjectList",
          title: "获奖项目",
          align: "center"
        },
        {
          colKey: "awardsType",
          title: "奖励种类",
          align: "center"
        },
        {
          colKey: "awardsLevel",
          title: "奖项级别",
          align: "center"
        },
        {
          colKey: "awardsGrade",
          title: "获奖等级",
          align: "center"
        },
        {
          colKey: "awardsDate",
          title: "获奖时间",
          align: "center"
        },
        {
          colKey: "publishDept",
          title: "颁奖单位",
          align: "center"
        },
        // {
        //   colKey: "declareDeptName",
        //   title: "填报单位",
        //   align: "center"
        // },
        {
          colKey: "awardsMemberList",
          title: "参与人员",
          align: "center"
        },

        // {
        //   colKey: "createTime",
        //   title: "创建时间",
        //   align: "center"
        // },
        {
          colKey: "awardsStatus",
          title: "奖励状态",
          align: "center",
          fixed: 'right'
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 140,
        }
      ],
      dataLoading: false,
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination, pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
    };
  },
  created() {
    this.getList();
  },
  methods:{
    getList() {
      if(this.deptId){
        this.dataLoading = true;
        this.$api.cgzh.awards.list(this.queryParams).then(response => {
          this.data = response.rows;
          this.pagination.total = response.total;
          this.dataLoading = false;
        }).catch((e) => {
          this.dataLoading = false;
          this.$message.error(e.toString());
        });
      }else if(this.idCard){
        this.dataLoading = true;
        this.$api.cgzh.awards.getJoinList(this.queryParams).then(response => {
          this.data = response.rows;
          this.pagination.total = response.total;
          this.dataLoading = false;
        }).catch((e) => {
          this.dataLoading = false;
          this.$message.error(e.toString());
        });
      }
    },
  }
}
</script>

<style scoped>

</style>
